# Maintainer:
pkgname=cvise
pkgver=2.8.0
pkgrel=2
_llvmver=16
pkgdesc="Python port of C-Reduce, for program testcase minimisation"
url="https://github.com/marxin/cvise"
arch="all"
license="NCSA"
depends="
	cmd:clang-format
	py3-chardet
	py3-pebble
	py3-psutil
	unifdef
	"
makedepends="
	clang$_llvmver-dev
	clang$_llvmver-static
	cmake
	flex
	llvm$_llvmver-dev
	llvm$_llvmver-static
	samurai
	"
checkdepends="
	py3-pytest-forked
	py3-pytest-xdist
	"
subpackages="$pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/marxin/cvise/archive/refs/tags/v$pkgver.tar.gz"

build() {
	export CC=clang-$_llvmver
	export CXX=clang++-$_llvmver
	export CFLAGS="${CFLAGS/-fstack-clash-protection} -O2 -DNDEBUG"
	export CXXFLAGS="${CXXFLAGS/-fstack-clash-protection} -O2 -DNDEBUG"

	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build
}

check() {
	cd build
	# simple_deduction: for some reason it checks for a short string but gets a wall of text in a reduced case
	pytest -c /dev/null -n auto --forked -k 'not test_simple_reduction'
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	# remove tests
	rm -r "$pkgdir"/usr/share/cvise/tests
	python3 -m compileall -fq "$pkgdir"/usr/share/cvise
}

pyc() {
	pkgdesc="Precompiled Python bytecode for ${subpkgname%-pyc}"
	install_if="${subpkgname%-pyc}=$pkgver-r$pkgrel pyc"

	cd "$pkgdir"
	local IFS='
'
	# shellcheck disable=2046
	amove $(find usr/share/cvise -type d -name __pycache__)
}

sha512sums="
7e2dee2001aacb96cf5ffdb62047d229e23273fd26f34648e23ab4374bf6cae149f13db529494ce8d2d16555a0d2143487923c57f4b303b0ab1f678ffcff6f6e  cvise-2.8.0.tar.gz
"
